package cn.kailangtu.dataspot.data;

import android.os.SystemClock;
import android.util.Log;
import org.greenrobot.eventbus.EventBus;
import org.litepal.LitePal;
import java.util.HashMap;
import java.util.Map;
import cn.kailangtu.commonevents.eventEntity.DataBeanChangedEvent;
import cn.kailangtu.commonevents.eventEntity.SystemErrCodeEvent;
import cn.kailangtu.commonevents.eventEntity.ViewShowSwitchEvent;
import cn.kailangtu.commontools.APPSPUtils;
import cn.kailangtu.commontools.CommonUtils;
import cn.kailangtu.commontools.DataUtils;
import cn.kailangtu.commontools.DateTimeUtils;
import cn.kailangtu.dataspot.AppBasicMethod;
import cn.kailangtu.dataspot.db.ExceptionLogEntity;
import cn.kailangtu.dataspot.db.OptionLogEntity;
import cn.kailangtu.dataspot.db.SwitchLogEntity;
import cn.kailangtu.dataspot.total.TotalData;
import cn.kailangtu.modbus.ModbusSlave;
import cn.kailangtu.serialutils.api.DIManager;

public class HighData {

    private int add_single_3584,add_single_3585,add_single_3586,add_single_3587,add_single_3588,add_single_3589;

    long openTime = 0;

    private DataBeanEx add_3499 = new DataBeanEx(3499);
    private DataBeanEx add_3500 = new DataBeanEx(3500);
    private DataBeanEx add_3501 = new DataBeanEx(3501);
    private DataBeanEx add_3502 = new DataBeanEx(3502);
    private DataBeanEx add_3503 = new DataBeanEx(3503);
    private DataBeanEx add_3504 = new DataBeanEx(3504);
    private DataBeanEx add_3505 = new DataBeanEx(3505);
    private DataBeanEx add_3506 = new DataBeanEx(3506);
    private DataBeanEx add_3507 = new DataBeanEx(3507);
    private DataBeanEx add_3508 = new DataBeanEx(3508);
    private DataBeanEx add_3509 = new DataBeanEx(3509);
    private DataBeanEx add_3510 = new DataBeanEx(3510);
    private DataBeanEx add_3511 = new DataBeanEx(3511);
    private DataBeanEx add_3512 = new DataBeanEx(3512);
    private DataBeanEx add_3513 = new DataBeanEx(3513);
    private DataBeanEx add_3514 = new DataBeanEx(3514);
    private DataBeanEx add_3515 = new DataBeanEx(3515,2);
    private DataBeanEx add_3526 = new DataBeanEx(3526);
    private DataBeanEx add_3527 = new DataBeanEx(3527);
    private DataBeanEx add_3528 = new DataBeanEx(3528);
    private DataBeanEx add_3529 = new DataBeanEx(3529);
    private DataBeanEx add_4500 = new DataBeanEx(4500);
    private DataBeanEx add_4501 = new DataBeanEx(4501);
    private DataBeanEx add_4502 = new DataBeanEx(4502);
    private DataBeanEx add_4503 = new DataBeanEx(4503);
    private DataBeanEx add_4504 = new DataBeanEx(4504);
    private DataBeanEx add_4505 = new DataBeanEx(4505);
    private DataBeanEx add_4506 = new DataBeanEx(4506);
    private DataBeanEx add_4507 = new DataBeanEx(4507);
    private DataBeanEx add_4508 = new DataBeanEx(4508);
    private DataBeanEx add_4509 = new DataBeanEx(4509);
    private DataBeanEx add_4510 = new DataBeanEx(4510);
    private DataBeanEx add_4511 = new DataBeanEx(4511);
    private DataBeanEx add_4512 = new DataBeanEx(4512);
    private DataBeanEx add_4513 = new DataBeanEx(4513);
    private DataBeanEx add_4514 = new DataBeanEx(4514);
    private DataBeanEx add_4515 = new DataBeanEx(4515);
    private DataBeanEx add_4516 = new DataBeanEx(4516);
    private DataBeanEx add_4517 = new DataBeanEx(4517);
    private DataBeanEx add_4518 = new DataBeanEx(4518);
    private DataBeanEx add_4519 = new DataBeanEx(4519);
    private DataBeanEx add_4520 = new DataBeanEx(4520);
    private DataBeanEx add_4521 = new DataBeanEx(4521);
    private DataBeanEx add_4522 = new DataBeanEx(4522);
    private DataBeanEx add_4523 = new DataBeanEx(4523);
    private DataBeanEx add_4524 = new DataBeanEx(4524);
    private DataBeanEx add_4525 = new DataBeanEx(4525);
    private DataBeanEx add_4526 = new DataBeanEx(4526);
    private DataBeanEx add_4527 = new DataBeanEx(4527);
    private DataBeanEx add_4528 = new DataBeanEx(4528);
    private DataBeanEx add_4529 = new DataBeanEx(4529);
    private DataBeanEx add_4530 = new DataBeanEx(4530);
    private DataBeanEx add_4531 = new DataBeanEx(4531);
    private DataBeanEx add_4532 = new DataBeanEx(4532);
    private DataBeanEx add_4533 = new DataBeanEx(4533);
    private DataBeanEx add_4534 = new DataBeanEx(4534);
    private DataBeanEx add_4535 = new DataBeanEx(4535);
    private DataBeanEx add_4536 = new DataBeanEx(4536);
    private DataBeanEx add_4537 = new DataBeanEx(4537);
    private DataBeanEx add_4538 = new DataBeanEx(4538);
    private DataBeanEx add_4539 = new DataBeanEx(4539);
    private DataBeanEx add_4570 = new DataBeanEx(4570);
    private DataBeanEx add_4571 = new DataBeanEx(4571);
    private DataBeanEx add_4572 = new DataBeanEx(4572);
    private DataBeanEx add_4573 = new DataBeanEx(4573);
    private DataBeanEx add_4574 = new DataBeanEx(4574);
    private DataBeanEx add_4550 = new DataBeanEx(4550);
    private DataBeanEx add_4551 = new DataBeanEx(4551);
    private DataBeanEx add_4552 = new DataBeanEx(4552);
    private DataBeanEx add_4553 = new DataBeanEx(4553);
    private DataBeanEx add_3595 = new DataBeanEx(3595);
    private DataBeanEx add_3584 = new DataBeanEx(3584);
    private DataBeanEx add_3585 = new DataBeanEx(3585);
    private DataBeanEx add_3586 = new DataBeanEx(3586);
    private DataBeanEx add_3587 = new DataBeanEx(3587);
    private DataBeanEx add_3588 = new DataBeanEx(3588);
    private DataBeanEx add_3589 = new DataBeanEx(3589);


    private static HighData instance;
    public static HighData getInstance(){
        if(instance == null)
        {
            instance = new HighData();
        }

        return instance;
    }

    Map<Integer ,DataBeanEx> map = new HashMap<>();
    private HighData(){
        openTime = System.currentTimeMillis();
        map.put(add_3499.getAddress(),add_3499);
        map.put(add_3500.getAddress(),add_3500);
        map.put(add_3501.getAddress(),add_3501);
        map.put(add_3502.getAddress(),add_3502);
        map.put(add_3503.getAddress(),add_3503);
        map.put(add_3504.getAddress(),add_3504);
        map.put(add_3505.getAddress(),add_3505);
        map.put(add_3506.getAddress(),add_3506);
        map.put(add_3507.getAddress(),add_3507);
        map.put(add_3508.getAddress(),add_3508);
        map.put(add_3509.getAddress(),add_3509);
        map.put(add_3510.getAddress(),add_3510);
        map.put(add_3511.getAddress(),add_3511);
        map.put(add_3512.getAddress(),add_3512);
        map.put(add_3513.getAddress(),add_3513);
        map.put(add_3514.getAddress(),add_3514);
        map.put(add_3515.getAddress(),add_3515);
        map.put(add_3526.getAddress(),add_3526);
        map.put(add_3527.getAddress(),add_3527);
        map.put(add_3528.getAddress(),add_3528);
        map.put(add_3529.getAddress(),add_3529);
        map.put(add_4500.getAddress(),add_4500);
        map.put(add_4501.getAddress(),add_4501);
        map.put(add_4502.getAddress(),add_4502);
        map.put(add_4503.getAddress(),add_4503);
        map.put(add_4504.getAddress(),add_4504);
        map.put(add_4505.getAddress(),add_4505);
        map.put(add_4506.getAddress(),add_4506);
        map.put(add_4507.getAddress(),add_4507);
        map.put(add_4508.getAddress(),add_4508);
        map.put(add_4509.getAddress(),add_4509);
        map.put(add_4510.getAddress(),add_4510);
        map.put(add_4511.getAddress(),add_4511);
        map.put(add_4512.getAddress(),add_4512);
        map.put(add_4513.getAddress(),add_4513);
        map.put(add_4514.getAddress(),add_4514);
        map.put(add_4515.getAddress(),add_4515);
        map.put(add_4516.getAddress(),add_4516);
        map.put(add_4517.getAddress(),add_4517);
        map.put(add_4518.getAddress(),add_4518);
        map.put(add_4519.getAddress(),add_4519);
        map.put(add_4520.getAddress(),add_4520);
        map.put(add_4521.getAddress(),add_4521);
        map.put(add_4522.getAddress(),add_4522);
        map.put(add_4523.getAddress(),add_4523);
        map.put(add_4524.getAddress(),add_4524);
        map.put(add_4525.getAddress(),add_4525);
        map.put(add_4526.getAddress(),add_4526);
        map.put(add_4527.getAddress(),add_4527);
        map.put(add_4528.getAddress(),add_4528);
        map.put(add_4529.getAddress(),add_4529);
        map.put(add_4530.getAddress(),add_4530);
        map.put(add_4531.getAddress(),add_4531);
        map.put(add_4532.getAddress(),add_4532);
        map.put(add_4533.getAddress(),add_4533);
        map.put(add_4534.getAddress(),add_4534);
        map.put(add_4535.getAddress(),add_4535);
        map.put(add_4536.getAddress(),add_4536);
        map.put(add_4537.getAddress(),add_4537);
        map.put(add_4538.getAddress(),add_4538);
        map.put(add_4539.getAddress(),add_4539);
        map.put(add_4570.getAddress(),add_4570);
        map.put(add_4571.getAddress(),add_4571);
        map.put(add_4572.getAddress(),add_4572);
        map.put(add_4573.getAddress(),add_4573);
        map.put(add_4574.getAddress(),add_4574);
        map.put(add_4550.getAddress(),add_4550);
        map.put(add_4551.getAddress(),add_4551);
        map.put(add_4552.getAddress(),add_4552);
        map.put(add_4553.getAddress(),add_4553);
        map.put(add_3595.getAddress(),add_3595);
        map.put(add_3584.getAddress(),add_3584);
        map.put(add_3585.getAddress(),add_3585);
        map.put(add_3586.getAddress(),add_3586);
        map.put(add_3587.getAddress(),add_3587);
        map.put(add_3588.getAddress(),add_3588);
        map.put(add_3589.getAddress(),add_3589);

        totla();

    }

    public void readNewData(byte[] data)
    {
        Log.d("SOSOSOSOSOSO","::"+ data.length);
        boolean hasChanged = false;
        for(Integer key : map.keySet())
        {
            DataBeanEx value =  map.get(key);
            if(data.length == 71) {
                value.processData故障数据1(data);
                ModbusSlave.processNewData(3499,data);
                NewDataContainer.getInstance().setMultiValue(3499,data);
                if(APPSPUtils.getInstance().getLastMainPage() == 2) {
                    proceErrLow();
                }
                else{
                    proceErrHigh();
                }
            }
            else if(data.length == 165) {
                value.processData4500(data);
                ModbusSlave.processNewData(4500,data);
                NewDataContainer.getInstance().setMultiValue(4500,data);
                ModbusSlave.setInited(true);
            }
            else if(data.length == 99){
                Log.d("SHOOTLEE_COM2", "收到："+CommonUtils.ByteArrayToHexString(data));
                ModbusSlave.processNewData(0,data);
                NewDataContainer.getInstance().setMultiValue(0,data);
            }
            if(value.isChanged())
            {
                hasChanged = true;
            }
        }
        if(hasChanged) {
            EventBus.getDefault().post(new DataBeanChangedEvent(0, 0, 0));
        }

        setTotalValue();
        procKeyboard();
        processSwitchData();
    }

    public int getValue(Integer address){
        if(map.containsKey(address))
        {
            return map.get(address).getValue();
        }
        return 0;
    }

    public void setVaule(Integer address,int value)
    {
        if(map.containsKey(address))
        {
            DataBeanEx data =  map.get(address);
            data.setValue(value);
        }
    }




    static int lastErrValue = 1;
    String errTitle = "";
    String errMsg = "";
    public void proceErrHigh()
    {
        String err = "";
        DataBeanEx exSource =  map.get(3503);
        DataBeanEx exErr1 = map.get(3500);
        DataBeanEx exErr2 = map.get(3501);
        DataBeanEx exErr3 = map.get(3502);
        // if(exSource.getValue() )

        if(exSource.getValue() >1 && exSource.getValue() != lastErrValue)
        {
            lastErrValue = exSource.getValue();
            switch(exSource.getValue())
            {
                case 2:
                    err =  "短路故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "短路故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
                case 3:
                    err =  "过载故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "过载故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
                case 4:
                    err = "远方分励 ";
                    errTitle  = "远方分励";
                    errMsg = "";
                    break;
                case 5:
                    err = "过压故障         " + "系统电压: " + exErr1.getValue()+"V";
                    errTitle = "过压故障";
                    errMsg = "系统电压: " + exErr1.getValue()+"V";
                    break;
                case 6:
                    err = "欠压故障         " + "系统电压: " + exErr1.getValue()+"V";
                    errTitle = "欠压故障";
                    errMsg = "系统电压: " + exErr1.getValue()+"V";
                    break;
                case 7:
                    err = "温度开路 ";
                    errTitle  = "温度开路";
                    errMsg = "";
                    break;
                case 8:
                    err = "低压侧故障 ";
                    errTitle  = "低压侧故障";
                    errMsg = "";
                    break;
                case 9:
                    err = "粘连故障 " + "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";
                    errTitle  = "粘连故障";
                    errMsg = "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";;
                    break;
                case 10:
                    err = "触点故障 " + "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";
                    errTitle  = "触点故障";
                    errMsg = "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";;
                    break;
                case 11:
                    err = "不平衡 " + "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";
                    errTitle  = "不平衡";
                    errMsg = "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";;
                    break;
                case 12:
                    err = "风电故障 ";
                    errTitle  = "风电故障";
                    errMsg = "";
                    break;
                case 13:
                    err = "瓦斯故障 ";
                    errTitle  = "瓦斯故障";
                    errMsg = "";
                    break;
                case 15:
                    err =  "超温保护 " + "温度: " + exErr1.getValue()+"℃";
                    errTitle  = "超温保护";
                    errMsg = "温度: " + exErr1.getValue()+"℃";
                    break;
                case 16:
                    err =  "绝缘故障  " + "温度: " + exErr1.getValue()+"K";
                    errTitle  = "绝缘故障";
                    errMsg = "电阻值: " + exErr1.getValue()+"K";
                    break;
                case 17:
                    err =  "绝缘断开  " + "温度: " + exErr1.getValue()+"K";
                    errTitle  = "绝缘断开";
                    errMsg = "电阻值: " + exErr1.getValue()+"K";
                    break;
                case 18:
                    err =  "过流故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "过流故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
                case 19:
                    err =  "接线柱温度故障 " + "温度: " + exErr1.getValue()+"℃";
                    errTitle  = "接线柱温度故障";
                    errMsg = "温度: " + exErr1.getValue()+"℃";
                    break;
                case 20:
                    err =  "断相故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "断相故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
            }

        }
        if(err != null && err.length()>0)
        {
            int id =  LitePal.max(ExceptionLogEntity.class,"logNumber", Integer.class);
            ExceptionLogEntity newEntity = new ExceptionLogEntity();
            newEntity.setLogNumber(id+1);
            newEntity.setLogTime(DateTimeUtils.longToYMDHMS(System.currentTimeMillis()));
            newEntity.setLogContent(err);

            newEntity.setDataSource(exSource.getValue());
            newEntity.setDataErr1(exErr1.getValue());
            newEntity.setDataErr2(exErr2.getValue());
            newEntity.setDataErr3(exErr3.getValue());

            newEntity.save();


            AppBasicMethod.getInstance().processExceptionLog();
        }

        if(exSource.getValue() <= 1) {
            errTitle = "";
            errMsg = "";
            lastErrValue = 1;
        }
        EventBus.getDefault().post(new SystemErrCodeEvent(exSource.getValue(), errTitle, errMsg));
    }

    public void proceErrLow()
    {
        String err = "";
        DataBeanEx exSource =  map.get(3503);
        DataBeanEx exErr1 = map.get(3500);
        DataBeanEx exErr2 = map.get(3501);
        DataBeanEx exErr3 = map.get(3502);
        // if(exSource.getValue() )

        if(exSource.getValue() >1 && exSource.getValue() != lastErrValue)
        {
            lastErrValue = exSource.getValue();
            switch(exSource.getValue())
            {
                case 2:
                    err =  "短路故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "短路故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
                case 3:
                    err =  "过载故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "过载故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
                case 4:
                    err = "低压分闸 ";
                    errTitle  = "低压分闸";
                    errMsg = "";
                    break;
                case 5:
                    err = "过压故障         " + "系统电压: " + exErr1.getValue()+"V";
                    errTitle = "过压故障";
                    errMsg = "系统电压: " + exErr1.getValue()+"V";
                    break;
                case 6:
                    err = "欠压故障         " + "系统电压: " + exErr1.getValue()+"V";
                    errTitle = "欠压故障";
                    errMsg = "系统电压: " + exErr1.getValue()+"V";
                    break;
                case 7:
                    err = "温度断开 ";
                    errTitle  = "温度断开";
                    errMsg = "";
                    break;
                case 8:
                    err =  "漏电故障  " + "温度: " + exErr1.getValue()+"K";
                    errTitle  = "漏电故障";
                    errMsg = "电阻值: " + exErr1.getValue()+"K";
                    break;

                case 11:
                    err = "不平衡 " + "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";
                    errTitle  = "不平衡";
                    errMsg = "IA: " + exErr1.getValue()+"A"+ " IB: " + exErr2.getValue()+"A"+ " IC: " + exErr3.getValue()+"A";;
                    break;
                case 12:
                    err = "风电故障 ";
                    errTitle  = "风电故障";
                    errMsg = "";
                    break;
                case 13:
                    err = "瓦斯故障 ";
                    errTitle  = "瓦斯故障";
                    errMsg = "";
                    break;
                case 15:
                    err =  "漏电闭锁  " + "温度: " + exErr1.getValue()+"K";
                    errTitle  = "漏电闭锁";
                    errMsg = "电阻值: " + exErr1.getValue()+"K";
                    break;
                case 16:
                    err =  "过流故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "过流故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
                case 17:
                    err =  "温度故障 " + "温度: " + exErr1.getValue()+"℃";
                    errTitle  = "温度故障";
                    errMsg = "温度: " + exErr1.getValue()+"℃";
                    break;
                case 18:
                    err =  "接线柱温度故障 " + "温度: " + exErr1.getValue()+"℃";
                    errTitle  = "接线柱温度故障";
                    errMsg = "温度: " + exErr1.getValue()+"℃";
                    break;
                case 19:
                    err =  "断相故障 IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    errTitle= "断相故障";
                    errMsg = "IA: "+ exErr1.getValue()+"A IB: "+exErr2.getValue()+"A IC: "+exErr3.getValue()+"A";
                    break;
            }

        }
        if(err != null && err.length()>0)
        {
            int id =  LitePal.max(ExceptionLogEntity.class,"logNumber", Integer.class);
            ExceptionLogEntity newEntity = new ExceptionLogEntity();
            newEntity.setLogNumber(id+1);
            newEntity.setLogTime(DateTimeUtils.longToYMDHMS(System.currentTimeMillis()));
            newEntity.setLogContent(err);

            newEntity.setDataSource(exSource.getValue());
            newEntity.setDataErr1(exErr1.getValue());
            newEntity.setDataErr2(exErr2.getValue());
            newEntity.setDataErr3(exErr3.getValue());

            newEntity.save();


            AppBasicMethod.getInstance().processExceptionLog();
        }

        if(exSource.getValue() <= 1) {
            errTitle = "";
            errMsg = "";
            lastErrValue = 1;
        }
        EventBus.getDefault().post(new SystemErrCodeEvent(exSource.getValue(), errTitle, errMsg));
    }



    int voltageValueA,voltageValueB,voltageValueC;
    int electricValueA,electricValueB,electricValueC;
    private void setTotalValue()
    {
        voltageValueA = getValue(3506);
        voltageValueB = getValue(3507);
        voltageValueC = getValue(3508);

        electricValueA = getValue(3509);
        electricValueB = getValue(3510);
        electricValueC = getValue(3511);

    }

    private void totla()
    {

        new Thread(new Runnable() {
            @Override
            public void run() {
                int index = 0;

                int indexMain = 0;
                while(true){
                    TotalData.record(voltageValueA,voltageValueB,voltageValueC,electricValueA,electricValueB,electricValueC);

                    if(indexMain >= APPSPUtils.getInstance().getChatRefreshTime())
                    {
                        indexMain = 0;
                        TotalData.totalSecond(10, APPSPUtils.getInstance().getChatRefreshTime(),0);
                        TotalData.totalSecond(15, APPSPUtils.getInstance().getChatRefreshTime(),1);
                    }


                    SystemClock.sleep(1000);
                    index++;
                    indexMain++;

                }
            }
        }).start();
    }

    int lastHazhaValue = 0;
    private void processSwitchData()
    {

        if((System.currentTimeMillis() - openTime ) > 10000) {
            openTime = System.currentTimeMillis();
            int currentHazhaValue = getValue(3504);
            Log.d("ABABABABAB","processSwitchData,"+currentHazhaValue);
            if (lastHazhaValue != currentHazhaValue) {
                Log.d("SHOOTEE_SWITCH","不一样了："+currentHazhaValue);
                lastHazhaValue = currentHazhaValue;
                String content = currentHazhaValue == 0 ? "进行了分闸操作":"进行了合闸操作";
                int id = LitePal.max(SwitchLogEntity.class, "logNumber", Integer.class);
                SwitchLogEntity entity = new SwitchLogEntity();
                entity.setLogContent( content);
                entity.setLogNumber(id + 1);
                entity.setLogTime(DateTimeUtils.longToYMDHMS(System.currentTimeMillis()));
                entity.setOptionType(0);
                boolean aaa =  entity.save();
            Log.d("SHOOTEE_SWITCH","记录结果："+id);
            }
        }
    }



    public int getAdd_single_3584() {
        return add_single_3584;
    }

    public boolean setAdd_single_3584(int add_single_3584) {
        if(this.add_single_3584 != add_single_3584) {
            this.add_single_3584 = add_single_3584;
            return true;
        }
        return false;
    }

    public int getAdd_single_3585() {
        return add_single_3585;
    }

    public boolean setAdd_single_3585(int add_single_3585) {
        if(this.add_single_3585 != add_single_3585) {
            this.add_single_3585 = add_single_3585;
            return true;
        }
        return false;
    }

    public int getAdd_single_3586() {
        return add_single_3586;
    }

    public boolean setAdd_single_3586(int add_single_3586) {
        if(this.add_single_3586 != add_single_3586) {
            this.add_single_3586 = add_single_3586;
            return true;
        }
        return false;
    }

    public int getAdd_single_3587() {
        return add_single_3587;
    }

    public boolean setAdd_single_3587(int add_single_3587) {
        if(this.add_single_3587 != add_single_3587) {
            this.add_single_3587 = add_single_3587;
            return true;
        }
        return false;
    }

    public int getAdd_single_3588() {
        return add_single_3588;
    }

    public boolean setAdd_single_3588(int add_single_3588) {
        if(this.add_single_3588 != add_single_3588) {
            this.add_single_3588 = add_single_3588;
            return true;
        }
        return false;
    }

    public int getAdd_single_3589() {
        return add_single_3589;
    }

    public boolean setAdd_single_3589(int add_single_3589) {
        if(this.add_single_3589 != add_single_3589) {
            this.add_single_3589 = add_single_3589;
            return true;
        }
        return false;
    }

    boolean hasChanged = false;
    int lastValue1 = 0;
    int lastValue2 = 0;
    int lastValue3 = 0;
    private void procKeyboard()
    {
        int  ad3499  =  getValue(3499);
        int[] bit3499 = DataUtils.getBits16(ad3499);
        EventBus.getDefault().post(new ViewShowSwitchEvent(bit3499[0] == 0,
                bit3499[1] == 0,
                bit3499[2] == 0,
                bit3499[3] == 0,
                bit3499[4] == 0,
                bit3499[5] == 0,
                bit3499[6] == 0,
                bit3499[7] == 0));
        hasChanged = false;
        int currValue1 = bit3499[8];
        int currValue2 = bit3499[9];
        int currValue3 = bit3499[10];
        if(lastValue1 != currValue1)
        {
            lastValue1 = currValue1;
            hasChanged = true;
        }
        if(lastValue2 != currValue2)
        {
            lastValue2 = currValue2;
            hasChanged = true;
        }
        if(lastValue3 != currValue3)
        {
            lastValue3 = currValue3;
            hasChanged = true;
        }
        if(hasChanged)
        {
            DIManager.getInstance().newValue(lastValue1,lastValue2,lastValue3);
        }
    }



}
